package tests;

import common.Utils;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;

public class PostPage extends Utils {
    public static String url = "http://47.93.222.41:58080/index.html";
    public PostPage() {
        super(url);
    }

    /*
    查询帖子 - 登录之后点击前端技术，点击最上方的帖子，显示帖子相应内容
     */
    public void selectPost() {
        driver.findElement(By.cssSelector("#topBoardList > li:nth-child(4) > a > span.nav-link-title")).click();
        driver.findElement(By.cssSelector("#artical-items-body > div:nth-child(1) > div > div.col > div.text-truncate > a > strong")).click();
//        查询帖子内容
        driver.findElement(By.cssSelector("#details_article_content > p"));
//        查询最新评论这个小标题
        driver.findElement(By.cssSelector("#bit-forum-content > div.page-body > div > div > div:nth-child(2) > h3"));
//        driver.quit();
    }

    /*
    编辑帖子
     */
    public void editPost() throws InterruptedException {
//        点击首页
        driver.findElement(By.cssSelector("#nav_board_index > a > span.nav-link-title")).click();
//        点击发布帖子
        driver.findElement(By.cssSelector("#bit-forum-content > div.page-header.d-print-none > div > div > div.col-auto.ms-auto.d-print-none > div > a.btn.btn-primary.d-none.d-sm-inline-block.article_post")).click();
//        选择编辑类型
        driver.findElement(By.cssSelector("#article_post_borad")).click();
//        选择福利待遇
        driver.findElement(By.cssSelector("#article_post_borad > option:nth-child(8)")).click();
//        编辑
        Thread.sleep(3000);
        driver.findElement(By.cssSelector("#article_post_title")).sendKeys("福利待遇");
//        通过鼠标操作来实现
//        1.鼠标先挪动到编辑区域
//        2.双击鼠标
//        3.输入内容
        WebElement element = driver.findElement(By.cssSelector("#edit-article > div.CodeMirror.cm-s-default.CodeMirror-wrap.CodeMirror-empty > div.CodeMirror-scroll > div.CodeMirror-sizer > div > div > div > div.CodeMirror-code > div > pre"));
        Actions actions = new Actions(driver);
        actions.doubleClick(element).perform();  // 在页面看到效果
//        actions.keyDown(Keys.DELETE).perform();
        actions.moveToElement(element).sendKeys("最好能躺在家里睡大觉一个月能给我100万").perform();
        Thread.sleep(3000);
//        点击发布
        WebElement element1 = driver.findElement(By.cssSelector("#article_post_submit"));
        Actions actions1 = new Actions(driver);
        actions1.click(element1).perform();
        Thread.sleep(3000);
//        driver.quit();
    }
}
